$(function(){
	var url={
		company:"{:url('adminapi/Company/companyList')}",
		passenger:"{:url('adminapi/Passenger/passengerList')}"
	}
	var company_list=`<option>请选择公司</option>`
	Load()
	$.ajax({
			type:'post',
			data:{
				page:1,
				pagenum:99999
			},
			url:url.company,
			success:function(res){
				Load(1)
				if(res.code==1){
					for(var i=0;i<res.data.length;i++){
						company_list+=`<option value='${res.data[i].company_id}'>${res.data[i].company_name}</option>`
					}
					$('.company').html(company_list)
				}else{
					
				}
			},
			error:function(){
				Err('请求失败')
			}
		})
	var brandid=$('brand select').val();
	$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:null
			},
			success:function(res){
				console.log(res);
				$('.brand select').html(res);
			}
		});
	$('.brand select').on('change',function(){
		var brandid=$(this).val();
		var brand = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:brandid
			},
			success:function(res){
				console.log(res);
				  layer.close(brand);
					$('.model select').html(res);
			}
		});
	})
	$('.model select').on('change',function(){
		var model = layer.load(1, {
		  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		var modelid=$(this).val();
		console.log(modelid)
		if(modelid){
		$.ajax({
			method: "POST",
			url:"{:url('car/brands')}",
			data:{
				id:modelid
			},
			success:function(res){
				 $('.series select').html(res)
			}
		});
		}else{
			$('.series select').html('')
		}
		layer.close(model);
	})
	$('.company').on('change',function(){
		Load()
		console.log($(this).val())
		var where_json={}
		where_json.company_id=['in',$(this).val()]
		var passenger_list=`<option>请选择申请人</option>`
		$.ajax({
			type:'post',
			data:{
				page:1,
				pagenum:99999,
				where_json:JSON.stringify(where_json)
			},
			url:url.passenger,
			success:function(res){
				console.log(res)
				Load(1)
				if(res.code==1){
					for(var i=0;i<res.data.length;i++){
						passenger_list+=`<option value='${res.data[i].passenger_id}'>${res.data[i].name}</option>`
					}
					$('.user_id').html(passenger_list)
				}else{
					
				}
			},
			error:function(){
				Load(1)
				Err('请求失败')
			}
		})
	})
	
	$('.sub_audit').on('click',function(){
		sendForm($(this), 1,'{:url("audit")}');
	})
})
